package com.jinxin.platform.cdperprotypay.support;

import com.alibaba.fastjson.JSON;
import com.jinxin.platform.base.common.annotation.RegBusiness;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdperprotypay.mapper.ChargeDetailMapper;
import com.jinxin.platform.cdperprotypay.pojo.form.ChargeDetailForm;
import com.jinxin.platform.cdperprotypay.pojo.vo.ChargeDetailVO;
import com.jinxin.platform.cdperprotypay.pojo.vo.PaysVo;
import com.jinxin.platform.cdperprotypay.service.impl.ChargeDetailServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : zhangpeng
 * @date : 2020-07-28 14:21:30
 **/
@Slf4j
@Service
@RegBusiness(moduleKey = "cdpropertypay", className = "ChargeAllRpcService")
public class ChargeAllRpcService {

    @Resource
    ChargeDetailMapper chargeDetailMapper;

    @Resource
    ChargeDetailServiceImpl chargeDetailService;

    public JsonResult findOwe2App(Map map) {
        ChargeDetailForm chargeDetailForm = new ChargeDetailForm();
        chargeDetailForm.setRoomId(map.get("roomId") + "");
        List<ChargeDetailVO> oweList = chargeDetailMapper.find2App(chargeDetailForm);
        List<ChargeDetailVO> chargeDetailVOS = chargeDetailService.newOwe(oweList);
        return JsonResult.ok(JSON.toJSONString(chargeDetailVOS));
    }

    public JsonResult findPays2Year(Map map) {
        log.info("年数据分析参数:{}", map);
        if (map.get("dataTime") == null) {
            log.info("请求参数为空：{}", map);
            return JsonResult.error("请求参数为空");
        }
        PaysVo pays2Year = chargeDetailMapper.findPays2Year(map.get("dataTime") + "", "未缴费");
        PaysVo pays2Year1 = chargeDetailMapper.findPays2Year(map.get("dataTime") + "", "已缴费");
        Integer total = chargeDetailMapper.getTotal(map.get("dataTime") + "");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("nopay", pays2Year.getSubtotal());
        hashMap.put("pay", pays2Year1.getSubtotal());
        hashMap.put("noroom", pays2Year.getRooms() + "");
        hashMap.put("rooms", (total - pays2Year.getRooms()) + "");
        log.info("年数据分析返回结果：{}", hashMap);
        return JsonResult.ok(hashMap);
    }

    public JsonResult findPays2Month(Map map) {
        log.info("月数据分析参数:{}", map);
        if (map.get("dataTime") == null) {
            log.info("请求参数为空：{}", map);
            return JsonResult.error("请求参数为空");
        }
        PaysVo pays2Year = chargeDetailMapper.findPays2Month(map.get("dataTime") + "", "未缴费");
        PaysVo pays2Year1 = chargeDetailMapper.findPays2Month(map.get("dataTime") + "", "已缴费");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("nopay", pays2Year.getSubtotal());
        hashMap.put("pay", pays2Year1.getSubtotal());
        hashMap.put("noroom", pays2Year.getRooms() + "");
        hashMap.put("rooms", pays2Year1.getRooms() + "");
        log.info("月数据分析返回结果：{}", hashMap);
        return JsonResult.ok(hashMap);
    }

}
